/**
 * This file is Copyright © 2008 Software Craftsmen Limited. All Rights Reserved.
 */
package com.softwarecraftsmen.generators;

import com.softwarecraftsmen.functors.Optional;
import static com.softwarecraftsmen.functors.Optional.None;
import com.softwarecraftsmen.functors.UnaryReturningFunctor;
import org.jetbrains.annotations.NotNull;

public class TransformGenerator<T, V> extends AbstractGenerator<V>
{
	private final Generator<T> generator;
	private final UnaryReturningFunctor<T, V> transformFunctor;

	public TransformGenerator(final @NotNull Generator<T> generator, final @NotNull UnaryReturningFunctor<T, V> transformFunctor)
	{
		this.generator = generator;
		this.transformFunctor = transformFunctor;
		None = None();
	}

	@NotNull
	public Optional<V> next()
	{
		final Optional<T> mayBeAValue = generator.next();
		return mayBeAValue.ifHasSomethingUseItElseReturnNone(transformFunctor);
	}
}
